Conditions | 14 |
Total Lines | 91 |
Code Lines | 68 |
Lines | 10 |
Ratio | 10.99 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like EditFacturaCliente.js ➔ businessDocViewSave often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | |||
99 | } |
||
100 | }); |
||
101 | } |
||
102 | |||
103 | async function businessDocViewSave() |
||
104 | { |
||
105 | $("#btn-document-save").prop("disabled", true); |
||
106 | var tipoPago = await cargarTipoPago(); |
||
107 | var datosPago = JSON.parse(tipoPago); |
||
108 | var ncfTipoPagoCliente = $("#formEditFacturaCliente select[name=ncftipopago]").val(); |
||
109 | var readOnlySelects = ($("#formSalesDocumentLine #doc_idestado").val() === '11'); |
||
110 | let selectOptionsPagos = ""; |
||
111 | $.each(datosPago.pagos, function (i, value) { |
||
112 | let defaultSelected = ((value.codigo === '17' && ncfTipoPagoCliente === '') || ncfTipoPagoCliente === value.codigo) ? 'selected' : ''; |
||
113 | let noSelected = ($("#formSalesDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
114 | selectOptionsPagos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
115 | }); |
||
116 | |||
117 | var tipoMovimiento = await cargarTipoMovimiento(); |
||
118 | var datosMovimiento = JSON.parse(tipoMovimiento); |
||
119 | |||
120 | let selectOptionsMovimientos = ""; |
||
121 | $.each(datosMovimiento.movimientos, function (i, value) { |
||
122 | let defaultSelected = (value.codigo === '1') ? 'selected' : ''; |
||
123 | let noSelected = ($("#formSalesDocumentLine #doc_idestado").val() === '11' && defaultSelected !== 'selected') ? ' disabled' : ''; |
||
124 | selectOptionsMovimientos += '<option value="'+value.codigo+'"'+defaultSelected+noSelected+'>'+value.descripcion+'</option>'; |
||
125 | }); |
||
126 | |||
127 | let message = '<div class="form-content">\n' + |
||
128 | ' <form class="form" role="form">\n' + |
||
129 | ' <div class="form-group">\n' + |
||
130 | ' <label for="ncftipopago">Tipo de Pago</label>\n' + |
||
131 | ' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
||
132 | selectOptionsPagos + |
||
133 | ' </select>\n' + |
||
134 | ' </div>\n' + |
||
135 | ' <div class="form-group">\n' + |
||
136 | ' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
||
137 | ' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
||
138 | selectOptionsMovimientos + |
||
139 | ' </select>\n' + |
||
140 | ' </div>\n' + |
||
141 | ' </form>\n' + |
||
142 | ' </div>'; |
||
143 | |||
144 | executeModal( |
||
145 | 'completeNCFData', |
||
146 | 'Complete la información faltante', |
||
147 | message, |
||
148 | 'default', |
||
149 | 'saveBussinessDocument' |
||
150 | ); |
||
151 | |||
152 | |||
153 | // bootbox.dialog({ |
||
154 | // title: "Complete la información faltante", |
||
155 | // message: '<div class="form-content">\n' + |
||
156 | // ' <form class="form" role="form">\n' + |
||
157 | // ' <div class="form-group">\n' + |
||
158 | // ' <label for="ncftipopago">Tipo de Pago</label>\n' + |
||
159 | // ' <select class="custom-select" id="ncftipopago" name="ncftipopago"'+readOnlySelects+'>\n' + |
||
160 | // selectOptionsPagos + |
||
161 | // ' </select>\n' + |
||
162 | // ' </div>\n' + |
||
163 | // ' <div class="form-group">\n' + |
||
164 | // ' <label for="ncftipomovimiento">Tipo de Movimiento</label>\n' + |
||
165 | // ' <select class="custom-select" id="ncftipomovimiento" name="ncftipomovimiento"'+readOnlySelects+'>\n' + |
||
166 | // selectOptionsMovimientos + |
||
167 | // ' </select>\n' + |
||
168 | // ' </div>\n' + |
||
169 | // ' </form>\n' + |
||
170 | // ' </div>', |
||
171 | // buttons: [ |
||
172 | // { |
||
173 | // label: "Guardar", |
||
174 | // className: "btn btn-primary", |
||
175 | // callback: function () { |
||
176 | // var data = {}; |
||
177 | // $.each($("#" + businessDocViewFormName).serializeArray(), function (key, value) { |
||
178 | // data[value.name] = value.value; |
||
179 | // }); |
||
180 | // data['ncftipopago'] = $('form #ncftipopago').val(); |
||
181 | // data['ncftipomovimiento'] = $('form #ncftipomovimiento').val(); |
||
182 | // data.action = "save-document"; |
||
183 | // data.lines = getGridData(); |
||
184 | // |
||
185 | // $.ajax({ |
||
186 | // type: "POST", |
||
187 | // url: businessDocViewUrl, |
||
188 | // dataType: "text", |
||
189 | // data: data, |
||
190 | // success: function (results) { |
||
229 | // }); |